//
//  WCAuthoriModel.m
//  winretailzctdealerPlugin
//
//  Created by zhangjikuan on 2020/11/18.
//

#import "WCAuthoriModel.h"
#import <WCCoreFramework/WCGlobalSingleton.h>
#import <GUI/WinUIContext.h>

@implementation WCAuthoriModel
#pragma mark - Private
+ (WCAuthoriModel *)_itemWith:(NSString *)title details:(NSString *)details {
    WCAuthoriModel *model = [WCAuthoriModel new];
    model.title = title;
    model.details = details;
    model.showArrow = NO;
    model.textFieldAble = NO;
    model.rowHeight = 30;
    return model;
}

+ (WCAuthoriModel *)_itemWith:(NSString *)title imageUrl:(NSString *)imageUrl {
    WCAuthoriModel *model = [WCAuthoriModel new];
    model.title = title;
    model.imageUrl = imageUrl;
    model.placeHolderImage = @"authori_placeholder";
    model.rowHeight = 214.5 * kWCAUTOSIZESCALEY;
    return model;
}

#pragma mark - Public
+ (UIColor *)authorizationStatusTextColor:(WCGetAuthorizeInfoResponse *)info {
    NSString *status = [NSString stringWithFormat:@"%@", info.status];
    if ([status isEqualToString:@"0"]) {
        return Win_F_Color(3);
    } else if ([status isEqualToString:@"1"]) {
        return [UIColor colorWithHexString:@"#187D2D"];
    } else if ([status isEqualToString:@"2"]) {
        return Win_F_Color(8);
    }
    return Win_F_Color(3);
}

+ (NSString *)authorizationStatus:(WCGetAuthorizeInfoResponse *)info {
    NSString *status = [NSString stringWithFormat:@"%@", info.status];
    if ([status isEqualToString:@"0"]) {
        return NLOCAL(@"authorization_waiting");
    } else if ([status isEqualToString:@"1"]) {
        return NLOCAL(@"authorization_pass");
    } else if ([status isEqualToString:@"2"]) {
        return [NSString stringWithFormat:@"%@, 原因：%@",NLOCAL(@"authorization_fail"),info.reason];
    }
    return @"";
}

+ (NSArray <WCAuthoriModel *> *)titleDataSource {
    WCAuthoriModel *titleItem = [WCAuthoriModel new];
    titleItem.title = NLOCAL(@"authorization_base_info");
    titleItem.rowHeight = 50;
    return @[titleItem];
}

+ (NSArray <WCAuthoriModel *> *)idCardInfoDataSource:(WCGetAuthorizeInfoResponse *)info {
    
    WCAuthoriModel *name    = [self _itemWith:NLOCAL(@"authorization_name2")
                                      details:info.name];
    
    WCAuthoriModel *idNum   = [self _itemWith:NLOCAL(@"authorization_idNum2")
                                      details:info.identityNo];
    
    WCAuthoriModel *from    = [self _itemWith:NLOCAL(@"authorization_id_valid_from2")
                                      details:info.validFrom];
    
    WCAuthoriModel *end     = [self _itemWith:NLOCAL(@"authorization_id_valid_end2")
                                      details:info.validEnd];
    return @[name, idNum, from, end];
}


+ (NSArray <WCAuthoriModel *> *)idCardImageDataSource:(WCGetAuthorizeInfoResponse *)info {
    
    WCAuthoriModel *handle = [self _itemWith:NLOCAL(@"authorization_id_handle")
                                     imageUrl:info.handheldIdCardUrl];
    
    WCAuthoriModel *front = [self _itemWith:NLOCAL(@"authorization_id_front")
                                    imageUrl:info.idCardUrl];
    
    WCAuthoriModel *back = [self _itemWith:NLOCAL(@"authorization_id_back")
                                   imageUrl:info.idCardBackUrl];
    
    WCAuthoriModel *author =  [self _itemWith:NLOCAL(@"authorization_authorization")
                                      imageUrl:info.url];
    
    return @[handle, front, back, author];
}

+ (NSArray <WCAuthoriModel *> *)editIdCardInfoDataSource:(WCGetAuthorizeInfoResponse *)info
{
    CGFloat rownHeight = 45.0f;
    WCAuthoriModel *nameItem = [WCAuthoriModel new];
    nameItem.title = NLOCAL(@"authorization_name");
    nameItem.placeHodler = NLOCAL(@"authorization_input_name");
    nameItem.details = info.name;
    nameItem.showArrow = NO;
    nameItem.rowHeight = rownHeight;
    
    WCAuthoriModel *idCardItem = [WCAuthoriModel new];
    idCardItem.placeHodler = NLOCAL(@"authorization_input_idNum");
    idCardItem.title = NLOCAL(@"authorization_idNum");
    idCardItem.details = info.identityNo;
    idCardItem.showArrow = NO;
    idCardItem.rowHeight = rownHeight;

    WCAuthoriModel *idValidFromItem = [WCAuthoriModel new];
    idValidFromItem.title = NLOCAL(@"authorization_id_valid_from");
    idValidFromItem.placeHodler = NLOCAL(@"authorization_id_valid_placehodler");
    idValidFromItem.details = info.validFrom;
    idValidFromItem.showArrow = YES;
    idValidFromItem.rowHeight = rownHeight;

    WCAuthoriModel *idValidEndItem = [WCAuthoriModel new];
    idValidEndItem.title = NLOCAL(@"authorization_id_valid_end");
    idValidEndItem.placeHodler = NLOCAL(@"authorization_id_valid_placehodler");
    idValidEndItem.details = info.validEnd;
    idValidEndItem.showArrow = YES;
    idValidEndItem.rowHeight = rownHeight;

    return  @[nameItem, idCardItem, idValidFromItem, idValidEndItem];
}

+ (NSArray <WCAuthoriModel *> *)editIdCardImageDataSource:(WCGetAuthorizeInfoResponse *)info {
    CGFloat rownHeight = 219.0f;
    WCAuthoriModel *handIdCard = [WCAuthoriModel new];
    handIdCard.title = NLOCAL(@"authorization_id_handle");
    handIdCard.imageUrl = info.handheldIdCardUrl;
    handIdCard.placeHolderImage = @"authorized_upload_id_handle";
    handIdCard.uploadImageType = UploadImageTypeHandle;
    handIdCard.rowHeight = rownHeight;
    
    WCAuthoriModel *idCardFront = [WCAuthoriModel new];
    idCardFront.title = NLOCAL(@"authorization_id_front");
    idCardFront.imageUrl = info.idCardUrl;
    idCardFront.placeHolderImage = @"authorized_upload_id_front";
    idCardFront.uploadImageType = UploadImageTypeFront;
    idCardFront.rowHeight = rownHeight;

    WCAuthoriModel *idCardBack = [WCAuthoriModel new];
    idCardBack.title = NLOCAL(@"authorization_id_back");
    idCardBack.imageUrl = info.idCardBackUrl;
    idCardBack.placeHolderImage = @"authorized_upload_id_back";
    idCardBack.uploadImageType = UploadImageTypeBack;
    idCardBack.rowHeight = rownHeight;

    return  @[handIdCard, idCardFront, idCardBack];

}

+ (NSArray <WCAuthoriModel *> *)editAuthoriDataSource:(WCGetAuthorizeInfoResponse *)info {
    WCAuthoriModel *model = [[WCAuthoriModel alloc] init];
    model.imageUrl = info.url;
    model.placeHolderImage = @"upload_author";
    model.rowHeight = 512.0f;
    return @[model];
}

@end
